/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package management;

import java.util.*;

/**
 *
 * @author Cucnth
 */
public class IsFile
{
    private Queue<Byte> queue;
    private boolean endFile;

    public boolean getEndFile()
    {
        return endFile && queue.isEmpty();
    }

    public void setEndFile(boolean endFile)
    {
        this.endFile = endFile;
    }

    public IsFile(Queue queue, boolean endFile)
    {
        this.queue = queue;
        this.endFile = endFile;
    }

    public IsFile()
    {
        this(new LinkedList<Byte>(), false);
    }

    public synchronized byte getByte() throws Exception
    {
        while(queue.isEmpty())
        {
            wait();
        }

        return queue.poll();
    }

    public synchronized void setByte(byte b) throws Exception
    {
        this.queue.offer(b);
        notify();
    }
}
